import React from "react";
//引入路由
import { Route, Routes, Navigate, NavLink } from "react-router-dom";
//引入组件
import Home from "./pages/Home";
import About from "./pages/About";
//引入一般组件   对NavLink的封装
export default function App() {
  const handleclassName = (isActive) => {
    return isActive ? "list-group-item css" : "list-group-item";
  };
  return (
    <div>
      <div className="row">
        <div className="col-xs-offset-2 col-xs-8">
          <div className="page-header">
            <h2>React Router Demo</h2>
          </div>
        </div>
      </div>
      <div className="row">
        <div className="col-xs-2 col-xs-offset-2">
          <div className="list-group">
            {/* react路由跳转 */}
            <NavLink
              className={({ isActive }) =>
                isActive ? "list-group-item css" : "list-group-item"
              }
              to={"/home"}
            >
              Home页面
            </NavLink>
            <NavLink
              className={({ isActive }) => handleclassName(isActive)}
              to={"/about"}
            >
              About页面
            </NavLink>
          </div>
        </div>
        <div className="col-xs-6">
          <div className="panel">
            <div className="panel-body">
              <Routes>
                <Route path={"/home"} element={<Home />} />
                <Route path={"/about"} element={<About />} />
                <Route path={"/"} element={<Navigate to="/about" />} />
              </Routes>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}
